package com.apes.fn.rpt.profit.grossProfitProcess.processor;

import com.apes.fn.rpt.profit.grossProfitProcess.CommonGrossProfitProcess;
import com.apes.fn.rpt.profit.grossProfitProcess.GrossProfitProcess;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 资金收入单处理器
 */
@Component
public class MoneyIncomeExpense extends CommonGrossProfitProcess implements GrossProfitProcess {

    @Override
    public String getSQL(Date taskDate) {
        return "SELECT X.CREATE_DATE, '其它' INCOME_CATEGORIES, '资金收入单' SERVE_TYPE_NAME, " +
                "      X.DEPT_ID, X.COMPANY_ID, SUM(X.INCOME_AMOUNT) AMOUNT, " +
                "      SUM(X.TIMES) TIMES, SUM(X.INCOME_AMOUNT) PRICE_TOTAL, 0 COST,0 vip_in,0 vip_out, " +
                "      0 CONSUMABLE_USE, 0 ACCESSORY_COST, 0 MAN_HOUR_COST, " +
                "      SUM(X.PLATFORM_MANAGEMENT_FEE) PLATFORM_MANAGEMENT_FEE, " +
                "      0 SUPPLY_CHAIN_MANAGEMENT_FEE" +
                "  FROM (SELECT TRUNC(A.APPROVE_DATE) CREATE_DATE, B.INCOME_AMOUNT, " +
                "                0 TIMES, A.COMPANY_ID, A.DEPT_ID, " +
                "                B.PLATFORM_MANAGEMENT_FEE " +
                "          FROM MONEY_INCOME A, MONEY_INCOME_ITEM B " +
                "          WHERE A.ID = B.MONEY_INCOME " +
                "            AND A.APPROVE_DATE >= to_date(:P_DATE, 'YYYY-mm-dd') " +
                "            AND A.APPROVE_DATE < to_date(:P_DATE, 'YYYY-mm-dd') + 1) X " +
                "GROUP BY X.CREATE_DATE, X.DEPT_ID, X.COMPANY_ID";
    }

    @Override
    public boolean support(String type) {
        return "MoneyIncome".equals(type);
    }
}
